package com.tianqi.common.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;

public enum GenderTypeEnum {
    MALE(1, "男"),
    FEMALE(0, "女");

    @EnumValue
    @JsonValue
    private final Integer code;
    private final String info;

    private GenderTypeEnum(Integer code, String info) {
        this.code = code;
        this.info = info;
    }

    public Integer getCode() {
        return this.code;
    }

    public String getInfo() {
        return this.info;
    }

    /**
     * 根据code获取性别
     *
     * @param code
     * @return
     */
    public static GenderTypeEnum getGenderByCode(Integer code) {
        GenderTypeEnum[] values = GenderTypeEnum.values();
        for (GenderTypeEnum genderEnum : values) {
            if (code.equals(genderEnum.getCode())) {
                return genderEnum;
            }
        }
        return null;
    }
}
